package cn.zswltech.gruul.common.enums;


import cn.zswltech.gruul.common.util.EnumsUtil;

public enum StatusCodeEnum implements EnumStatus {
    SUCCESS(200, "操作成功"),
    BUSSINESS_ERROR(0, "业务异常"),
    UNKNOW_ERROR(-1, "未知异常"),
    SYSTEM_ERROR(-2, "系统异常"),
    PARAM_ERROR(-3, "参数不正确"),
    DATABASE_ERROR(-4, "数据库异常"),
    ENCRYPT_ERROR(-5, "加解密异常"),
    CACHE_ERROR(-6, "缓存异常"),
    UNAUTHORIZED_ERROR(-7, "未授权"),
    NOT_FOUND_ERROR(-8, "请求不存在"),
    NEED_LOGIN(488, "登录信息已失效，需重新登录"), // 唯一用户登录
    SIGNATURE_INVALID(401002, "无效的用户签名"),
    SIGNATURE_EXPIRED(401001, "用户签名已过期"),
    PERMISSION_MENU_ERROR(403001, "用户无菜单权限"),
    PERMISSION_FUNCTION_ERROR(403002, "用户无功能权限"),
    PERMISSION_USER_NOT_EXIST(401004, "用户不存在"),
    PERMISSION_USER_LOCKED(401005, "用户被禁用"),;

    private int status;
    private String msg;

    private StatusCodeEnum(int status, String msg) {
        this.msg = msg;
        this.status = status;
    }

    public static StatusCodeEnum valueOf(int value) {
        StatusCodeEnum anEnum = (StatusCodeEnum) EnumsUtil.findEnumByValue(values(), value);
        if (anEnum == null) {
            anEnum = BUSSINESS_ERROR;
        }
        return anEnum;
    }

    @Override
    public int getStatus() {
        return status;
    }

    @Override
    public String getMsg() {
        return this.msg;
    }
}
